//
//  VisitorViewController.swift
//  Weibo10
//
//  Created by Leon on 15/10/14.
//  Copyright © 2015年 Leon. All rights reserved.
//

import UIKit
import SVProgressHUD
class VisitorViewController: UITableViewController {
    
    /// 访问视图
    var visitorView: visitorLoginView?

 /// 标记用户是否登录
    var userLogon = UserAccountViewModel.shareAccount.userLogon
    
    override func loadView() {
       
        userLogon ? super.loadView() : setNotLogon()
    }
    
    private func setNotLogon() {
        
        // 替换根试图
        visitorView = visitorLoginView()

        // 增加点击事件
        visitorView?.registerBtn.addTarget(self, action: "registerButtonClick", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.loginBrn.addTarget(self, action: "loginButtonClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        // 增加导航栏的item
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "registerButtonClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: "loginButtonClick")
        
        
        view = visitorView
        
    }
    
    
}

extension VisitorViewController {
    
    func registerButtonClick() {
        print("注册")
    }
    
    func loginButtonClick() {
        let nav = UINavigationController(rootViewController: OAuthViewController())
        
        presentViewController(nav, animated: true, completion:nil)

    }
    
    
}


